﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL_Class;

namespace NLLSite.Administrator.UserControl
{
    public partial class AddNewArticle : System.Web.UI.UserControl
    {
        BaiViet cre = new BaiViet();
        Article art; 
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }
        protected void Page_Init(object sender, EventArgs e)
        {
            lbxMenu.DataSource = LinqDataSource1;
            lbxMenu.DataBind();
        }
        protected void BtnAdd_Click(object sender, EventArgs e)
        {
            art = new Article();
            art.MenuID = 0;
            if(lbxMenu.SelectedValue!=""){
            art.MenuID = Convert.ToInt32(lbxMenu.SelectedValue);}
            art.Title = TxtTitle.Text;
            art.ThumbImage = TxtImage.Text;
            art.Description = Txtdes.Text;
            art.Content = CKEditor1.Text;
            art.CreateDate = DateTime.Now;
          
             if (CbxSlide.Checked == false)
            {
                  art.IsSilde =  false;
            }
            else
            {
                  art.IsSilde =  true;
            }

            if (CbxFront.Checked == false)
            {
                art.IsFrontPage = false;
            }
            else
            {
                 art.IsFrontPage = true;
            }

            art.AuthorID = 0;
            if (LbxAut.SelectedValue != "")
            {
                art.AuthorID = Convert.ToInt32(LbxAut.SelectedValue);
            }
            art.MetaTitle = TxtMetatit.Text;
            art.MetaDescription = TxtMetades.Text;
            art.MetaKeywords = TxtMetakey.Text;
            art.MetaRobots = TxtMetaro.Text;
            art.MetaAuthor = TxtMetaAut.Text;

            Lblchk.Text = cre.AddNewArticle(art);
            Response.Redirect("QuanlyBaiViet.aspx");
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Txtdes.Text = string.Empty;
            TxtImage.Text =string.Empty;
            TxtMetaAut.Text = string.Empty;
            TxtMetades.Text =string.Empty;
            TxtMetakey.Text = string.Empty;
            TxtMetaro.Text = string.Empty;
            TxtMetatit.Text = string.Empty;
            TxtTitle.Text = string.Empty;
            CbxFront.Checked = false;
            CbxSlide.Checked = false;
            CKEditor1.Text = string.Empty;
            Lblchk.Text = string.Empty;
        }

        protected void Ddlposi_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (Ddlposi.SelectedValue == "Chủ Đề")
            {
                lbxMenu.DataSource = LinqDataSource3;
                lbxMenu.DataBind();
            }
            else {
                lbxMenu.DataSource = LinqDataSource1;
                lbxMenu.DataBind();
            }
        }
    }
}